import http from '@/common/fetch';

// const { LIVE_API, LIVE_PASSPORT_API } = process.env;会报错...
// eslint-disable-next-line
const LIVE_API = process.env.LIVE_API;
// eslint-disable-next-line
const LIVE_PASSPORT_API = process.env.LIVE_PASSPORT_API;
const formatApiParams = (data) => data.join('/');

/**
 * 获取安卓iOS的下载链接
 */
// export const getAppDownloadLink = (params) => http.get(`${LIVE_PASSPORT_API}/v1/downloadInfo`, { params });

/**
 * 数据上报
 * @doc http://192.168.100.100:3000/project/29/interface/api/2605
 */
export const appChannelReport = (data) => http.post(`${LIVE_PASSPORT_API}/appchannel/up`, data);

/**
 * 用户等级列表
 * @doc http://192.168.100.100:3000/project/29/interface/api/2623
 */
export const getUserLevel = (config) => http.get(`${LIVE_PASSPORT_API}/user/getUserLevel`, config);

/**
 * 获取直播间列表
 * @doc http://yapi.qihang2021.cn:3000/project/47/interface/api/271
 */
export const getRoomList = (params) => http.get(`${LIVE_API}/v1.2/rooms/pc`, { params });

/**
 * 获取直播间的聊天记录
 */
export const getRoomHistoryMsg = (params) => http.get(`${LIVE_PASSPORT_API}/v10/rooms/getRoomHistoryMsg`, { params });

/**
 * 首页直播列表
 */
export const getLiveList = (params) => http.get('live/web/host/living', { params });

/**
  * 根据终端类型和位置获取Banner
  * @doc http://192.168.100.100:3000/project/47/interface/api/205
  * export const getBanners = (params) => http.get(`${LIVE_API}/v1.0/banner/getBanners`, { params });
  */
export const getBanners = (params) => http.get('news/web/banner/host/living', { params });

/**
  * 获取房间详情
  * @doc http://yapi.qihang2021.cn:3000/project/47/interface/api/259
  * export const getRoomDetail = (params) => http.get(`${LIVE_API}/v0.1/room/detail`, { params });
  */
export const getRoomDetail = (apiParams) => http.get(`live/web/host/roomid/${(formatApiParams(apiParams))}`);

export const getRoomDetailByUserId = (params) => http.get('live/web/host/log/detail', { params });

/**
 * 获取安卓的下载链接
 */
export const getAndroidDownloadLink = () => http.get('app/web/configsetup/androidTiYu');

/**
  * 获取ios的下载链接
  */
export const getIosDownloadLink = () => http.get('app/web/configsetup/iosTiYu');

/**
  * 合并获取安卓iOS的下载链接
  */
export const getAppDownloadLink = async () => {
  const [iosConfig, androidConfig] = await Promise.all([getIosDownloadLink(), getAndroidDownloadLink()]);
  const iosDownloadUrl = iosConfig?.data?.downloadUrl || '';
  const androidDownloadUrl = androidConfig?.data?.downloadUrl || '';
  return new Promise((resolve) => {
    resolve({
      data: {
        ios: iosDownloadUrl,
        android: androidDownloadUrl,
      },
    });
  });
};

// 获取礼品李彪
export const getGiftList = (type) => http.get(`/app/web/goods/list/${type}`);

// 下载时来源的渠道
export const getTrench = (channelCode = '') => http.get(`/app/web/channel/channelDownload?channelCode=${channelCode}`);

export const submitClickInfo = (p) => http({
  url: '/app/web/app/user/addSetUpLog',
  params: p,
  method: 'post',
});
